import java.util.Scanner;
public class Main{
  static  class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;

     TreeNode() {
     }

     public TreeNode(int val) {
         this.val = val;
     }

     public TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
     }
 }
    public static void preOrder(TreeNode root) {
        if (root == null) {
            return;
        }

        preOrder(root.left);
        preOrder(root.right);
        System.out.print(root.val + " ");
    }

    public static TreeNode buildTree(int[] preorder, int[] inorder) {
        if (preorder.length == 0) {
            return null;
        }
        return buildTreeChild(preorder, 0, inorder, 0, inorder.length - 1);
    }

    public static TreeNode buildTreeChild(int[] preorder, int pre, int[] inorder, int star, int end) {
        if (star > end || pre >= preorder.length) {
            return null;
        }

        TreeNode node = new TreeNode(preorder[pre]);
        int inorderIndex = found(inorder, preorder[pre], star,end);
        node.right = buildTreeChild(preorder, pre + 1, inorder, star, inorderIndex - 1);
        node.left = buildTreeChild(preorder, pre + 1 + inorderIndex - star, inorder, inorderIndex + 1, end);
        return node;
    }

    public  static  int found(int[] inorder,int a,int strat,int end){

        for(int i=strat;i<=end;i++){
            if(inorder[i]==a) return i;
        }
        return -1;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] preorder = new int[n];
        int[] inorder = new int[n];
        for (int i = 0; i < n; i++) {
            preorder[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            inorder[i] = sc.nextInt();
        }
        TreeNode root = buildTree(preorder, inorder);
        preOrder(root);
    }

 }